From 9ac3945baa265097603bd9d409d130bb82005394 Mon Sep 17 00:00:00 2001 From: secondl1ght <85003930+secondl1ght@users.noreply.github.com> Date: Tue, 16 Aug 2022 10:56:47 -0600 Subject: move lang selector from app header into settings page --- src/routes/[username]/settings.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/routes/[username]') diff --git a/src/routes/[username]/settings.svelte b/src/routes/[username]/settings.svelte index 5abe58e0..11e0977a 100644 --- a/src/routes/[username]/settings.svelte +++ b/src/routes/[username]/settings.svelte @@ -1,5 +1,5 @@ - + {#each $locales as locale} + + {/each} diff --git a/src/lib/i18n.js b/src/lib/i18n.js index fdf5de3c..3105c709 100644 --- a/src/lib/i18n.js +++ b/src/lib/i18n.js @@ -2,41 +2,40 @@ import { register, init, getLocaleFromNavigator } from 'svelte-i18n'; // The list of locales to look for // ADD ALL NEW LANGUAGE CODES TO THIS LIST -const localeCodes = ["en", "fr"]; +const localeCodes = ['en', 'fr']; // the default locale to use if none was found -const defaultLocale = "en"; +const defaultLocale = 'en'; // Adds a new locale based on its code function addLocale(localeCode) { - register(localeCode, () => import(`../locales/${localeCode}.json`)); + register(localeCode, () => import(`../locales/${localeCode}.json`)); } // Picks the default locale based on navigator locale and the list of available locales function pickLocale(navigatorLocale, availableLocales) { - // locale can be null the first time you load this - // return the default locale in that case - reloading should fix this - if (!navigatorLocale) - return defaultLocale; - - // determine langugage part of locale - // (e.g. if navigatorLocale is 'en-US', languageCode is 'en') - let dashIndex = navigatorLocale ? navigatorLocale.indexOf("-") : -1; - let languageCode; // navigator locale without the regional part - if (dashIndex === -1) { - languageCode = navigatorLocale; - } else { - languageCode = navigatorLocale.slice(0, dashIndex); - } - - // get locale - if (availableLocales.includes(navigatorLocale)) { - return navigatorLocale; - } else if (availableLocales.includes(languageCode)) { - return languageCode; - } else { - return navigatorLocale; - } + // locale can be null the first time you load this + // return the default locale in that case - reloading should fix this + if (!navigatorLocale) return defaultLocale; + + // determine langugage part of locale + // (e.g. if navigatorLocale is 'en-US', languageCode is 'en') + let dashIndex = navigatorLocale ? navigatorLocale.indexOf('-') : -1; + let languageCode; // navigator locale without the regional part + if (dashIndex === -1) { + languageCode = navigatorLocale; + } else { + languageCode = navigatorLocale.slice(0, dashIndex); + } + + // get locale + if (availableLocales.includes(navigatorLocale)) { + return navigatorLocale; + } else if (availableLocales.includes(languageCode)) { + return languageCode; + } else { + return navigatorLocale; + } } // add locales @@ -44,6 +43,6 @@ localeCodes.forEach(addLocale); let initialLocale = pickLocale(getLocaleFromNavigator(), localeCodes); init({ - fallbackLocale: defaultLocale, - initialLocale: initialLocale, + fallbackLocale: defaultLocale, + initialLocale: initialLocale }); diff --git a/src/locales/en.json b/src/locales/en.json index c5c36c4b..a44c202f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1,11 +1,10 @@ { - "langname": "English", - "nav": { - "howItWorks": "How It Works", - "faq": "FAQ", - "about": "About", - "startInSeconds": "Start in Seconds", - "signIn": "Sign In" -} - + "langname": "English", + "nav": { + "howItWorks": "How It Works", + "faq": "FAQ", + "about": "About", + "startInSeconds": "Start in Seconds", + "signIn": "Sign In" + } } diff --git a/src/locales/fr.json b/src/locales/fr.json index d2c9d758..9adc9488 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -1,11 +1,10 @@ { - "langname": "Français", -"nav": { - "howItWorks": "Comment Ça Fonctionne", - "faq": "FAQ", - "about": "À Propos", - "startInSeconds": "Commence en Secondes", - "signIn": "Connexion" -} - + "langname": "Français", + "nav": { + "howItWorks": "Comment Ça Fonctionne", + "faq": "FAQ", + "about": "À Propos", + "startInSeconds": "Commence en Secondes", + "signIn": "Connexion" + } } diff --git a/src/routes/[username]/settings.svelte b/src/routes/[username]/settings.svelte index 11e0977a..e4d7b0bf 100644 --- a/src/routes/[username]/settings.svelte +++ b/src/routes/[username]/settings.svelte @@ -44,10 +44,10 @@ {#if setting === 'account'} -
- - -
+
+ + +
diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index c5234c7d..5f9f1456 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -1,16 +1,16 @@